package com.ph.irp.stock.service.impl;

import java.util.Iterator;
import java.util.List;

import com.ph.irp.model.PStockStockinvoice;
import com.ph.irp.model.PStockStockinvoicedetail;
import com.ph.irp.stock.dao.StockInvoiceDAO;
import com.ph.irp.stock.dao.StockInvoiceDetailDAO;
import com.ph.irp.stock.service.StockInvoiceService;

public class StockInvoiceServiceImpl implements StockInvoiceService{
	
	private StockInvoiceDAO stockInvoiceDAOProxy;
	private StockInvoiceDetailDAO stockInvoiceDetailDAOProxy;
	

	public StockInvoiceDAO getStockInvoiceDAOProxy() {
		return stockInvoiceDAOProxy;
	}

	public void setStockInvoiceDAOProxy(StockInvoiceDAO stockInvoiceDAOProxy) {
		this.stockInvoiceDAOProxy = stockInvoiceDAOProxy;
	}

	public StockInvoiceDetailDAO getStockInvoiceDetailDAOProxy() {
		return stockInvoiceDetailDAOProxy;
	}

	public void setStockInvoiceDetailDAOProxy(
			StockInvoiceDetailDAO stockInvoiceDetailDAOProxy) {
		this.stockInvoiceDetailDAOProxy = stockInvoiceDetailDAOProxy;
	}

	@Override
	public void deleteStockInvoice(int stockInvoiceID) throws Throwable {
		// TODO Auto-generated method stub
		
	}

	@Override
	public List<PStockStockinvoice> getAllStockInvoiceList() throws Throwable {
		return stockInvoiceDAOProxy.getAllStockInvoiceList();
	}

	@Override
	public PStockStockinvoice getStockInvoiceByID() throws Throwable {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void updateStockInvoice(PStockStockinvoice stockInvoiceModel)
			throws Throwable {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void addStockInvoice(PStockStockinvoice stockInvoiceModel,
			List<PStockStockinvoicedetail> stockInvoiceDetailList)
			throws Throwable {
		// TODO Auto-generated method stub
		stockInvoiceDAOProxy.addStockInvoice(stockInvoiceModel);
//		取得新增发票的ID
		int stockInvoiceId = stockInvoiceDAOProxy.getStockInvoiceByNo(stockInvoiceModel.getInvoiceNo());
		Iterator it = stockInvoiceDetailList.iterator();
		while(it.hasNext()){
			PStockStockinvoicedetail stockInvoiceDetailModel = null;
			stockInvoiceDetailModel = (PStockStockinvoicedetail) it.next();
			stockInvoiceDetailModel.setStockInvoiceId(stockInvoiceId);
			
			stockInvoiceDetailDAOProxy.addStockInvoiceDetail(stockInvoiceDetailModel);
		}
		
	}

	@Override
	public List<PStockStockinvoice> getStockInvoiceList(
			PStockStockinvoice stockInvoiceModel) throws Throwable {
		return stockInvoiceDAOProxy.getStockInvoiceList(stockInvoiceModel);
	}

}
